// PM2 进程配置文件
module.exports = {
  apps: [
    {
      name: 'aide-backend',
      cwd: './backend',
      script: 'dist/index.js',
      instances: 1,
      exec_mode: 'fork',
      
      // 环境配置
      env: {
        NODE_ENV: 'production',
        PORT: 5000
      },
      
      // 自动重启配置
      autorestart: true,
      watch: false,
      max_memory_restart: '1G',
      min_uptime: '10s',
      max_restarts: 5,
      
      // 日志配置
      error_file: './logs/aide-error.log',
      out_file: './logs/aide-out.log',
      log_file: './logs/aide-combined.log',
      time: true,
      log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
      
      // 进程配置
      kill_timeout: 5000,
      listen_timeout: 3000,
      
      // 健康检查
      health_check_url: 'http://localhost:5000/health',
      health_check_grace_period: 3000,
      
      // 其他配置
      merge_logs: true,
      source_map_support: false,
      instance_var: 'INSTANCE_ID'
    }
  ],

  // 部署配置
  deploy: {
    production: {
      user: 'deploy',
      host: 'your-server.com',
      ref: 'origin/main',
      repo: 'https://github.com/your-username/aide.git',
      path: '/var/www/aide',
      'pre-deploy-local': '',
      'post-deploy': 'npm install && npm run build && pm2 reload ecosystem.config.js --env production',
      'pre-setup': ''
    }
  }
}
